package cn.com.lyb;



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson2.JSON;
import com.github.difflib.text.DiffRow;
import com.github.difflib.text.DiffRowGenerator;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class TextComparator {

    public static void main(String[] args) throws Exception {
        String text1 = "222\n" +
                "333\n" +
                "这是第一段文本，包含一些信息。";
        String text2 = "223\n" +
                "222\n" +
                "这是第一段文本，包含一些信息。";

        // 创建比较器
        DiffRowGenerator generator = DiffRowGenerator.create()
                .showInlineDiffs(true)
                .inlineDiffByWord(true)  // 新增
                .build();

        // 生成比较结果
        List<DiffRow> rows = generator.generateDiffRows(
                Arrays.asList(text1.split("\n")),
                Arrays.asList(text2.split("\n"))
        );

        Object json = JSON.toJSON(rows);
        System.out.println(json);


    }
}

